﻿package views
{
	import at.geoathome.text.TextFieldGenerator;
	import at.geoathome.ui.buttons.Button;
	import at.geoathome.ui.buttons.TextButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	public class GameSelectionView extends Sprite
	{
		private var _drawn:Boolean;
		private var _game:Game;
		// visual
		private var _game_selection_btn_a:Button;
		private var _game_selection_btn_b:Button;
		
		public function GameSelectionView(game:Game) 
		{
			_game = game;
			_drawn = false;
			hide();
			
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			if (visible)
				show();
		}
		
		
		private function draw():void 
		{
			if (_drawn) return;
			
			extractAssets();
			
			// draw something
			addChild(_game_selection_btn_a);
			_game_selection_btn_a.x = stage.stageWidth / 2 - 200;
			_game_selection_btn_a.y = (stage.stageHeight - _game_selection_btn_a.height)/2;
			_game_selection_btn_a.addEventListener(MouseEvent.MOUSE_UP, onSelectGameA);
			
			addChild(_game_selection_btn_b);
			_game_selection_btn_b.x = stage.stageWidth / 2 + 200;
			_game_selection_btn_b.y = (stage.stageHeight - _game_selection_btn_b.height)/2;
			_game_selection_btn_b.addEventListener(MouseEvent.MOUSE_UP, onSelectGameB);
			
			_drawn = true;
		}
		
		private function extractAssets():void
		{
			_game_selection_btn_a = new Button("GameSelectionButtonBgA");
			_game_selection_btn_b = new Button("GameSelectionButtonBgB");
		}
		
		public function show():void 
		{
			if (stage)
				draw();
			
			visible = true;
		}
		
		public function hide():void 
		{
			visible = false;
		}
		
		
		private function onSelectGameA(e:MouseEvent):void 
		{
			_game.changeStateToDefault();
			_game.startGame(Game.GAME_TYPE_A);
	
			hide();
		}
		
		private function onSelectGameB(e:MouseEvent):void 
		{
			_game.changeStateToDefault();
			_game.startGame(Game.GAME_TYPE_B);
			hide();
		}
	}
	
}